package cn.dduan.fool.design.pattern.great.single;

/**
 * 双重检验懒汉单例
 * <p>
 * 是否线程安全：是
 * 是否懒加载：是
 * 优点：synchronized 代码块优化执行时间，减少锁的粒度
 *
 * @author dduan
 * @version 1.0
 * @date 2023/3/17
 */
public class LazySingletonDoubleCheck {
    private static LazySingletonDoubleCheck lazySingletonDoubleCheck;

    private LazySingletonDoubleCheck() {
    }

    public static LazySingletonDoubleCheck getInstance() {
        if (lazySingletonDoubleCheck == null) {
            synchronized (LazySingletonDoubleCheck.class) {
                if (lazySingletonDoubleCheck == null) {
                    lazySingletonDoubleCheck = new LazySingletonDoubleCheck();
                }
            }
        }
        return lazySingletonDoubleCheck;
    }
}
